
<link rel="stylesheet" href="jquery/easyui/themes/default/easyui.css">
<link rel="stylesheet" href="jquery/easyui/themes/icon.css">
<link rel="stylesheet" href="dropzonefileupload/dropzone.css" >
<body>

<!-- <div>操作须知:</div> -->
<div id="calInfo" class="easyui-panel" title="" style="width:100%;">
	<div style="margin-bottom:5px">
<!--          <input class="easyui-textbox" name="materialModel" style="width:50%" data-options="label:'物料规格尺寸:',required:true">注意:输入数据为 长*宽*厚度 或者 长-宽-厚度
 -->     	 <select id="materialModel" name="materialModel" class="easyui-combogrid" style="width:50%" data-options="
                  panelWidth: 380,
                  required:true,
                  idField: 'id',
                  textField: 'text',
                  url: 'json/modelSize.json',
                  method: 'get',
                  columns: [[
                      {field:'text',title:'规格尺寸',width:80}
                  ]],
                  fitColumns: true,
                  label: '物料规格尺寸:',
                  labelPosition: 'left',
                  keyHandler: {
		            enter: function(e){
		            	fill($('#klfs').combogrid('getText'));
		            },
		            query: function (q) {
		            	
		            },
		            up: function (e) {
		                
		            },
		            down: function (e) {
		                
		            }
		        },
		        onClickRow:function(index,row){
		            $('#materialModel').combogrid('setText',row.text);
		        }
              ">
          </select>注意:输入数据为 长*宽*厚度 或者 长-宽-厚度
     </div>
     <div style="margin-bottom:5px">
         <input class="easyui-textbox" id="klSize" name="klSize" style="width:50%" data-options="label:'开料尺寸:',required:true">注意:输入数据为 长*宽*厚度 或者 长-宽-厚度
     </div>
     <div style="margin-bottom:5px">
         <input class="easyui-numberbox"  id="dblength" name="dblength" value="0" style="width:50%" data-options="label:'长度打边:',required:true,min:0,precision:1">注意:输入数据为数字
     </div>
     <div style="margin-bottom:5px">
         <input class="easyui-numberbox"  id="dbwidth" name="dbwidth" value="0" style="width:50%" data-options="label:'宽度打边:',required:true,min:0,precision:1">注意:输入数据为数字
     </div>
     <div style="margin-bottom:5px">
         <input class="easyui-numberbox"  id="lengthCut" name="lengthCut" value="0" style="width:50%" data-options="label:'长度可减少量:',required:true,min:0,precision:1">注意:输入数据为数字
     </div>
     <div style="margin-bottom:5px">
         <input class="easyui-numberbox"  id="widthCut" name="widthCut" value="0" style="width:50%" data-options="label:'宽度可减少量:',required:true,min:0,precision:1">注意:输入数据为数字
     </div>
     <div style="margin-bottom:5px">
         <input class="easyui-numberbox"  name="feedTotal" value="0" style="width:50%" data-options="label:'投料数:',required:true,min:0,precision:1">注意:输入数据为数字
     </div>
     <div class="easyui-panel" title="" style="width:100%;">
	     <!-- 图纸尺寸 -->
	     <div style="margin-bottom:5px">
	         <input class="easyui-textbox" type="text" id="picSize" name="picSize" style="width:50%" data-options="label:'图纸尺寸:',required:true">注意:输入数据为 长*宽*厚度 或者 长-宽-厚度
	     </div>
	     <div style="margin-bottom:5px">
	         <input class="easyui-numberbox" type="text" id="picLengthRate" name="picLengthRate" value="0" style="width:50%" data-options="label:'长度余量:',required:true,min:0,precision:1">注意:输入数据为数字
	     </div>
	     <div style="margin-bottom:5px">
	         <input class="easyui-numberbox" type="text" id="picWidthRate" name="picWidthRate" value="0" style="width:50%" data-options="label:'宽度余量:',required:true,min:0,precision:1">注意:输入数据为数字
	     </div>
     </div>
</div>
<div id="ruleInfo" class="easyui-panel" title="" style="width:100%;height:400px" >
	<a href="#" onclick="hideRule()">关闭</a>
	<img src="https://upload.shinehao.com.cn/201809261402431.png" style="width:100%;"/>
	<img src="https://upload.shinehao.com.cn/201809261402472.png" style="width:100%"/>
</div>
<div style="text-align:center;padding:5px 0">
  	<input type="checkbox" id="operatetips" checked/><span style="color:red">我已了解<a href="#" onclick="showRule()">操作规则</a></span>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="cal('x')" style="width:80px">横开</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="cal('y')" style="width:80px">竖开</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="cal('xy')" style="width:80px">双向</a>
</div>
每条料可开数:<span id="mtlkks" style="color:red"></span><br>
用料条数:<span id="feedTotal" style="color:red"></span><br>
建议开料尺寸:<span id="jyKlSize" style="color:red"></span>

<script src="https://upload.shinehao.com.cn/20180816150739jquery-1.8.3.min.js"></script>
<script src="https://upload.shinehao.com.cn/20180816145716jquery.easyui.min.js"></script>
<script src="https://upload.shinehao.com.cn/20180816151727easyui-lang-zh_CN.js"></script>
<script src="https://upload.shinehao.com.cn/20180816150641dropzone.min.js"></script>
<script src="js/base.js"></script>
<script>
function cal(str){
	if($('#operatetips').is(':checked')) {
		
	}else{
		alert("已阅读,请勾选");
		return;
	}
	var materialModel = $('#materialModel').combogrid('getText');//$("[name='materialModel']").val();
	var klSize = $("[name='klSize']").val();
	var dbLength = $("[name='dblength']").val();
	var dbWidth = $("[name='dbwidth']").val();
	var lengthCut = $("[name='lengthCut']").val();
	var widthCut = $("[name='widthCut']").val();
	var feedTotal = $("[name='feedTotal']").val();
	var result=0;
	var jyKlSize="";
	//规格长宽高
	var modelStrCleans = (materialModel.indexOf("*")>-1?materialModel.split("*"):materialModel.split("-"));
	var modelLengthClean = modelStrCleans[0];
	var modelWidthClean = modelStrCleans[1];
	//开料尺寸
	var klSizeStrCleans = (klSize.indexOf("*")>-1?klSize.split("*"):klSize.split("-"));
	var klSizeLengthClean = klSizeStrCleans[0];
	var klSizeWidthClean = klSizeStrCleans[1];
	
	if(str=="x"){
		result = menubuttonIndexTool.calResultForMTLKKS_x(materialModel,klSize,"物料类型",dbLength,dbWidth,widthCut,lengthCut);
		var resultDiff = menubuttonIndexTool.calResultForMTLKKS_x(materialModel,klSize,"物料类型",dbLength,dbWidth,0,0);
		//如果最小开料长宽大于最大长宽 则计算建议开料尺寸
		if(result>=resultDiff){
			//建议开料尺寸长度 = 最大规格宽度余量/(最多开料长度数量取整)+最小开料长度
			var maxTotal=parseInt((modelWidthClean-dbWidth)/(klSizeLengthClean-lengthCut));
			var jyLength = ((modelWidthClean-dbWidth)-maxTotal*(klSizeLengthClean-lengthCut))/maxTotal+(klSizeLengthClean-lengthCut);
			if(jyLength>klSizeLengthClean){
				jyLength=klSizeLengthClean;
			}
			//建议开料尺寸宽度 = 最大规格长度余量/(最多开料宽度数量-取整)
			var maxTotal=parseInt((modelLengthClean-dbLength)/(klSizeWidthClean-widthCut));
			var jyWidth = ((modelLengthClean-dbLength)-maxTotal*(klSizeWidthClean-widthCut))/maxTotal+(klSizeWidthClean-widthCut);
			if(jyWidth>klSizeWidthClean){
				jyWidth=klSizeWidthClean;
			}
			jyKlSize=((jyLength-0).toFixed(1)+"*"+(jyWidth-0).toFixed(1))
		}
	}
	if(str=="y"){
		result = menubuttonIndexTool.calResultForMTLKKS_y(materialModel,klSize,"物料类型",dbLength,dbWidth,widthCut,lengthCut);
		var resultDiff = menubuttonIndexTool.calResultForMTLKKS_y(materialModel,klSize,"物料类型",dbLength,dbWidth,0,0);
		//如果最小开料长宽大于最大长宽 则计算建议开料尺寸
		if(result>=resultDiff){
			//建议开料尺寸长度 = 最大规格长度余量/(最多开料长度数量-取整)
			var maxTotal=parseInt((modelLengthClean-dbLength)/(klSizeLengthClean-lengthCut));
			var jyLength = ((modelLengthClean-dbLength)-maxTotal*(klSizeLengthClean-lengthCut))/maxTotal+(klSizeLengthClean-lengthCut);
			if(jyLength>klSizeLengthClean){
				jyLength=klSizeLengthClean;
			}
			//建议开料尺寸宽度 = 最大规格宽度余量/(最多开料宽度数量-取整)
			var maxTotal=parseInt((modelWidthClean-dbWidth)/(klSizeWidthClean-widthCut));
			var jyWidth = ((modelWidthClean-dbWidth)-maxTotal*(klSizeWidthClean-widthCut))/maxTotal+(klSizeWidthClean-widthCut);
			if(jyWidth>klSizeWidthClean){
				jyWidth=klSizeWidthClean;
			}
			jyKlSize=((jyLength-0).toFixed(1)+"*"+(jyWidth-0).toFixed(1))
		}
	}
	if(str=="xy"){
		result = menubuttonIndexTool.calResultForMTLKKS_xy(materialModel,klSize,"物料类型",dbLength,dbWidth,widthCut,lengthCut);
		var resultDiff = menubuttonIndexTool.calResultForMTLKKS_xy(materialModel,klSize,"物料类型",dbLength,dbWidth,0,0);
		//如果最小开料长宽大于最大长宽 则计算建议开料尺寸
		if(result>=resultDiff){
			//最多纵项竖向放几个
			var maxTotalYY=parseInt((modelLengthClean-dbLength)/(klSizeLengthClean-lengthCut));
			//最多纵项横向放几个
			var maxTotalYX=parseInt((modelWidthClean-dbWidth)/(klSizeWidthClean-widthCut));
			/* 横向纵向排列最大可余量 */
			var maxXYRate=(modelWidthClean-dbWidth)-maxTotalYX*(klSizeWidthClean-widthCut);
			console.info(maxXYRate)
			//最大横向横放放几个
			var maxTotalXX=parseInt((modelWidthClean-dbWidth)/(klSizeLengthClean-lengthCut));
			/* 横向横向排列最大可余量 */
			var maxXXRate = (modelWidthClean-dbWidth)-maxTotalXX*(klSizeLengthClean-lengthCut);
			console.info(maxXXRate)
			//最多横项竖放放几个
			var maxTotalXY=parseInt(((modelLengthClean-dbLength)-maxTotalYY*(klSizeLengthClean-lengthCut))/(klSizeWidthClean-widthCut));
			/* 纵向最大可余量 标准*/
			var maxYRate = (modelLengthClean-dbLength)-maxTotalYY*(klSizeLengthClean-lengthCut)-maxTotalXY*(klSizeWidthClean-widthCut);
			console.info(maxYRate)
			//建议开料尺寸长度
			var realRate =(maxYRate>maxXXRate)?maxXXRate:maxYRate;
			var jyLength =(klSizeLengthClean-lengthCut)+realRate/maxTotalYY;
			if(jyLength>klSizeLengthClean){
				jyLength=klSizeLengthClean;
			}
			//建议开料尺寸宽度 
			var realRate =(maxYRate>maxXYRate)?maxXYRate:maxYRate;
			var jyWidth=(klSizeWidthClean-widthCut)+realRate/maxTotalYX;
			if(jyWidth>klSizeWidthClean){
				jyWidth=klSizeWidthClean;
			}
			jyKlSize=((jyLength-0).toFixed(1)+"*"+(jyWidth-0).toFixed(1))
		}
	}
	if(isNaN(result)){
		$("#mtlkks").text("输入信息有误,请检查输入内容");
		$("#jyKlSize").text("");
		return;
	}
	$("#mtlkks").text(result);
	//$("#feedTotal").text((feedTotal/result).toFixed(2));
	if(result==0){
		$("#feedTotal").text(0);
	}else{
		$("#feedTotal").text((feedTotal/result).toFixed(2));
	}
	$("#jyKlSize").text(jyKlSize);
}
/* 绑定blur事件 */
$(function(){
	$("[name='klSize']").prev().blur(function(){
		calKlSizeAndPicSize(1);
	})
	$("[name='picSize']").prev().blur(function(){
		calKlSizeAndPicSize(2);
	})
	$("[name='picLengthRate']").prev().blur(function(){
		calKlSizeAndPicSize(2);
	})
	$("[name='picWidthRate']").prev().blur(function(){
		calKlSizeAndPicSize(2);
	})
	//获取工程参数自动填充
	$.ajax({
        type: 'POST',
        url: "/weixin/project/getInfo",
        data: {},
        success: function(data){
        	if(data.data){
        		$("#widthCut").numberbox("setValue",data.data.widthCut);
    			$("#lengthCut").numberbox("setValue",data.data.lengthCut);
    			$("#dbwidth").numberbox("setValue",data.data.widthDb);
    			$("#dblength").numberbox("setValue",data.data.lengthDb);
    			$("#picLengthRate").numberbox("setValue",data.data.picLengthRate);
    			$("#picWidthRate").numberbox("setValue",data.data.picWidthRate);
        	}
        },
        dataType: "json"
      });
})
function calKlSizeAndPicSize(n){
	var klSize =  $("[name='klSize']").val();
	var klSizeLength = (klSize.indexOf("*")>-1?klSize.split("*"):klSize.split("-"))[0];
	var klSizeWidth = (klSize.indexOf("*")>-1?klSize.split("*"):klSize.split("-"))[1];
	var klSizeHeight = (klSize.indexOf("*")>-1?klSize.split("*"):klSize.split("-"))[2];
	if(klSizeHeight==undefined){klSizeHeight=0}
	var picSize = $("[name='picSize']").val();
	var picSizeLength = (picSize.indexOf("*")>-1?picSize.split("*"):picSize.split("-"))[0];
	var picSizeWidth = (picSize.indexOf("*")>-1?picSize.split("*"):picSize.split("-"))[1];
	
	var picLengthRate = $("[name='picLengthRate']").val();
	var picWidthRate = $("[name='picWidthRate']").val();
	//开料尺寸修改了
	if(n==1){
		if(klSize.length==0){return;}
		if(picLengthRate.length==0){return;}
		if(picWidthRate.length==0){return;}
		//计算图纸尺寸 前提长度余量和宽度余量有数值
		picSizeLength = klSizeLength-2*picLengthRate;
		picSizeWidth  = klSizeWidth -2*picWidthRate;
		$("#picSize").textbox("setValue",(picSizeLength*10/10).toFixed(1)+"*"+(picSizeWidth*10/10).toFixed(1)+"*"+klSizeHeight)
	}
	//图纸尺寸修改了
	if(n==2){
		//计算开料尺寸 前提图纸尺寸 长度余量和宽度余量有数值
		if(picSize.length==0){return;}
		klSizeLength=(picSizeLength-0)+2*picLengthRate;
		klSizeWidth =(picSizeWidth-0)+2*picWidthRate;
		$("#klSize").textbox("setValue",(klSizeLength*10/10).toFixed(1)+"*"+(klSizeWidth*10/10).toFixed(1)+"*"+(klSizeHeight?klSizeHeight:0))
	}
	
}
$(function(){
	$("#ruleInfo").parent().hide()
})
/* 操作规则 */
function showRule(){
	$("#ruleInfo").parent().show();
	$("#calInfo").parent().hide();
}
function hideRule(){
	$("#ruleInfo").parent().hide();
	$("#calInfo").parent().show();
}
</script>

</body>


























